package com.aki.ai_property.service.impl;

import com.aki.ai_property.dao.CleanDao;
import com.aki.ai_property.entity.Clean;
import com.aki.ai_property.service.intf.CleanService;
import com.aki.ai_property.vo.PageBean;
import com.aki.ai_property.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 34553
 * @date 2022/8/28
 */
@Service
public class CleanServiceImpl implements CleanService {
    @Autowired
    private CleanDao dao;

    @Override
    public Result save(Clean clean) {
        if (dao.save(clean) > 0) {
            return Result.ok("新增成功");
        }
        return Result.fail("新增失败");
    }

    @Override
    public Result update(Clean clean) {
        if (dao.update(clean) > 0) {
            return Result.ok("修改成功");
        }
        return Result.fail("修改失败");
    }

    @Override
    public Result delete(int id) {
        if (dao.delete(id) > 0) {
            return Result.ok("删除成功");
        }
        return Result.fail("删除成功");
    }

    @Override
    public PageBean selectPage(String name, int page, int limit) {

        if (name != null && name.length() > 0) {
            name = "%" + name + "%";
        }
        int start = (page - 1) * limit;

        return PageBean.ok(dao.selectCount(name), dao.selectPage(name, start, limit));
    }

    /** 查询总条数 */
    @Override
    public Result all() {
        return Result.ok(dao.all());
    }
}
